//
//  DatabaseModule.swift
//  GlassDatabase
//
//  Created by 李然 on 2022/7/13.
//

import MoyoungLib
import RealmSwift

let schemaVersion: UInt64 = 2

class DatabaseModule: NSObject, Modularable {
    
    var priority: ModulePriority = .high
    
    required override init() {
        super.init()
    }
    
    func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        return true
    }
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        
        // 数据库字段有更新，需增加 schemaVersion版本号
        let config = Realm.Configuration.init(schemaVersion: schemaVersion, migrationBlock: { migration, oldSchemaVersion in
            if oldSchemaVersion < 1 {
            }
        })
        Realm.Configuration.defaultConfiguration = config
        return true
    }
}

